/**
 * @created by zhangxs4 on 2019/01/14.
 * @description 客户灵活查询
 */
define([
	'./custom/widgets/js/yufpOrgTree.js',
	'./custom/widgets/js/yufpRoleSelector.js',
	'./libs/jsencrypt/jsencrypt.min.js',
	'./custom/widgets/js/yufpDptTree.js',
	'./custom/widgets/js/yufpExtTree.js'
	// './custom/plugins/YufpMgrSelector.js'
], function(require, exports) {
	/**
	 * 页面加载完成时触发
	 * @param hashCode 路由ID
	 * @param data 传递数据对象
	 * @param cite 页面站点信息
	 */
	var tags1 = [];
	exports.ready = function(hashCode, data, cite) {
		var level1RoleIds = "R0006,R0007,R0008"; //总行
		var level2RoleIds = "R0003,R0004,R0005"; //支行
		var level3RoleIds = "R0001,R0002,R0009"; //客户经理
		var roleLevel = '';
		var roleId = '';
		for (var i = 0; i < yufp.session.roles.length; i++) {
			if (yufp.session.roles[i].checked != null) {
				roleId = yufp.session.roles[i].code;
				if (level1RoleIds.indexOf(roleId) != -1) {
					roleLevel = '1';
				} else if (level2RoleIds.indexOf(roleId) != -1) {
					roleLevel = '2';
				} else if (level3RoleIds.indexOf(roleId) != -1) {
					roleLevel = '3';
				}
			}
		}
		var columnOptions = [];
		var chartTagOptions = [];
		var xchartTagOptions = [];
		var chartTargetOptions = [];
		var ychartTargetOptions = [];
		var customersColumnOptions = [];
		var firstOptions = [];
		var secondOptions = [];
		var thirdOptions = [];
		var fourOptions = [];
		var fiveOptions = [];
		var comboSelectOptions = [];
		var typeOptions = [];
		var numDataOptions = [];
		var countSumOptions = [];
		var textOptions = [];
		var selectOptions = [];
		var radioComboOptions = [];
		var labelOptions = [];
		var querysql = '';
		var graphSql = '';
		var graphInfo;
		var sumNamesOptions = [];
		// var queryAllResult = [];
		// yufp.lookup.reg('custBase_custType,IDENT_TYPE,custBase_corpNature,INDUSTRY_BIG_TYPE,INPUT_RGST_TYPE,cust_proper,INDUS_TYPE,CORP_SCALE,ECON_TYPE,HOLD_TYPE,CORP_SUBJ,BUSINESS_DETAIL,curr_code,NEW_CURR_CODE,CORP_SCALE_OLD');
		yufp.lookup.reg('CUST_GROUP_STATE');
		var vm = yufp.custom.vue({
			el: '#custFlexyQuery',
			data: function() {
				var me = this;
				return {
					collapse: true,
					widthsol: '0px',
					colv: {
						solcol: 1,
						spanTree: 4,
						spanS: 14,
						spanR: 6,
						spanTreeHidden: false
					},
					planConfVisible: false,
					progressDialogTitle: '进度条', // 进度条
					progressDialogVisible: false,
					progressDialogTimer: null,
					progressPercent: 0,
					progressVisible: false,
					exportVisible: false,
					progressStatus: '',
					loading: false,
					percentage: 1,
					solutionDialogClass: 'planConfDialog',
					closeSolutionDialogBtnText: '取消', // 方案编辑展示对话框的关闭按钮文字
					querySolutionRstBtnShowFlag: true, // 方案编辑展示对话框是否显示“查询结果”按钮
					saveSolutionBtnShowFlag: true, // 方案编辑展示对话框是否显示“保存方案”按钮
					resetSolutionBtnShowFlag: true, // 方案编辑展示对话框是否显示“重置方案”按钮
					pageHeight: yufp.frame.size().height + 'px',
					rptButton: !yufp.session.checkCtrl('rptPub'), // 发布报表选择按钮控制
					graphButton: !yufp.session.checkCtrl('graphPub'), // 发布报表选择按钮控制
					echartData: {}, // 图表预览
					formdata: {},
					queryFormdata: {},
					async: false,
					custGroupId: '',
					formDisabled: false,
					addCustGroupDialogVisible: false,
					custGroupformdata: {},
					selectcustGroupformdata: {},
					name: 'asdsad',
					proParam: {
						condition: JSON.stringify({
							userId: yufp.session.userId,
							orgCode: yufp.session.org.id
						})
					},
					param: {
						groupNo: '0',
						levelunit: '1'
					},
					list: [], // 方案的查询条件列表
					selectList: [], // 选中的作为查询条件的标签
					settinglist: [],
					setselectList: [], // 选中的作为查询条件的标签
					qryList: [], // 查询条件
					setlist: [], // 查询条件
					custtagList: [],
					solshow: true,
					pageData: {
						total: 0,
						page: 1,
						size: 10,
						layout: 'total, sizes, prev, pager, next, jumper',
						pageKey: 'page',
						sizeKey: 'size'
					},
					tags1: tags1,
					opRule: [{
						required: true,
						message: '操作符不能为空'
					}],
					signvRule: [{
						required: true,
						message: '属性不能为空'
					}],
					tagTemp: {
						custName: '',
						definedTag: ''
					},
					dialogTagForm: false,
					buttonsDisabled: false,
					showdelbtn: true,
					wfCommonParams: {
						sessionInstuCde: yufp.session.instu.code,
						sessionOrgCode: yufp.session.org.code,
						sessionLoginCode: yufp.session.user.loginCode
					},
					queryFields: [{
							placeholder: '客户群编号',
							field: 'clientsNO',
							type: 'input'
						},
						{
							placeholder: '客户群名称',
							field: 'clientsName',
							type: 'input'
						},
						{
							placeholder: '群成员类型',
							field: 'clientsType',
							type: 'input'
						}
					],
					optionData: [],
					summTableData: [],
					ssolutiontableColumns: [{
							label: '方案',
							prop: 'ssName',
							resizable: true
						}
						// { label: '创建人', prop: 'userName', resizable: true },
						// { label: '创建机构', prop: 'orgName', resizable: true }
					],
					// leftTreeDataUrl: backend.appOcaService + '/api/flexibleQuery/getIndexTree',
					ssolutionUrl: backend.appOcaService + '/api/flexibleQuerySolution/list',
					// selectCustGroupUrl: backend.custgroupService + '/api/ocrmfcicgbase/list',
					startUrl: '/api/flexibleQuery/asyncLoanExport',
					progressUrl: '/api/flexibleQuery/queryDownloadInfo',
					downloadUrl: '/api/flexibleQuery/downloadDepExcel',
					firstOptions: firstOptions,
					secondOptions: secondOptions,
					thirdOptions: thirdOptions,
					fourOptions: fourOptions,
					fiveOptions: fiveOptions,
					columnOptions: columnOptions,
					chartTagOptions: chartTagOptions,
					xchartTagOptions: xchartTagOptions,
					chartTargetOptions: chartTargetOptions,
					ychartTargetOptions: ychartTargetOptions,
					customersColumnOptions: customersColumnOptions,
					countSumOptions: countSumOptions,
					comboSelectOptions: comboSelectOptions,
					numDataOptions: numDataOptions,
					textOptions: textOptions,
					selectOptions: selectOptions,
					radioComboOptions: radioComboOptions,
					labelOptions: labelOptions,
					sumNamesOptions: sumNamesOptions,
					typeOptions: typeOptions,
					taskId: '',
					delay: 2000,
					dataParams: {
						roleLevel: roleLevel
					},

					filterTreedataValue: '', // 指标树过滤指标输入框框默认值
					orderOptions: [{
						key: '1',
						value: '不排序'
					}, {
						key: '2',
						value: '升序'
					}, {
						key: '3',
						value: '降序'
					}],
					dataSqlTemp: {
						ID: {
							signOp: ''
						}
					},
					incustomersTemp: {
						incustomers: ''
					},
					dataTemp: {},
					groupform: {
						firstgroup: '',
						secondgroup: '',
						thirdgroup: '',
						fourgroup: '',
						fivegroup: ''
					},
					chartTemp: {
						chartName: '',
						chartSize: '',
						chartType: ''
					},
					chartTagTemp: {
						chartTag: '',
						chartTarget: ''
					},
					ychartNameTemp: {
						ychartName: '',
						ychartBegin: '',
						xchartTag: '',
						ychartTarget: '',
						chartType: ''
					},
					solutionNameSetFormData: {
						ssName: ''
					},
					reportTemp: {
						reportName: ''
					},

					groupTemp: {},
					customersTemp: {
						custGroupName: '',
						custGroupType: '',
						customersColumn: '',
						groupMemberType: '',
						batchType: '',
						shareScope: '',
						remark: ''
					},
					ruless: {
						custGroupName: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						custGroupType: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						// customersColumn:[{required: true, message: '必填项', trigger: 'blur'}],
						groupMemberType: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						batchType: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}]
					},
					chartrule: {
						chartName: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						chartType: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}]
					},
					charttagrule: {
						chartTag: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						chartTarget: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}]
					},
					ychartrule: {
						ychartName: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						ychartBegin: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						xchartTag: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}],
						ychartTarget: [{
							required: true,
							message: '必填项',
							trigger: 'blur'
						}]
					},
					data: [],
					conditionAttrs: [],
					busiTypeFlag: [],
					qryarr: [],
					results: [],
					grouplist: [],
					groupnamelist: [],
					conlist: [],

					colunmNamelist: [{
						'name': '客户编号',
						'id': '',
						'ename': 'custIdBase',
						'fixedFlag': true
					}, {
						'name': '客户名称',
						'id': '',
						'ename': 'custNameBase',
						'fixedFlag': true
					}],
					resultColunmNamelist: [{
						'name': '客户编号',
						'id': '',
						'ename': 'custIdBase',
						'fixedFlag': true
					}, {
						'name': '客户名称',
						'id': '',
						'ename': 'custNameBase',
						'fixedFlag': true
					}],
					fieldDatas: [],
					qrylist: [],
					treedata: [], // 指标方案编辑对话框的指标树
					treedataLoaded: false, // 指标树是否加载完成
					treedataLoadedLoadInfoShow: false, // 指标树加载完成是否加载方案信息显示
					solutionlist: [], // 显示列列表
					activeName: 'first', // tab默认显示值
					limitNum: '', // 查询条数
					height: yufp.frame.size().height - 140,
					groupHeight: yufp.frame.size().height - 360,
					dialogVisible: false,
					dialogFormVisible1: false,
					dialogFormVisible2: false,
					showPrise: false,
					addcustomersdialogVisible: false,
					showRentPrise: false,
					pubbuttonsDisabled: false,
					closebuttonsDisabled: false,
					casedialogVisible: false,
					savebuttonsDisabled: false,
					customersbuttonsDisabled: false,
					incustomersdialogVisible: false,
					customersqrydialogVisible: false,
					solutionNameSetDialogVisible: false,
					selectCustGroupDialogVisible: false,
					viewType: 'DETAIL',
					selectedSsId: '', // 选择的方案ID
					selectedSsName: '', // 选择的方案名称
					async: false,
					viewTitle: yufp.lookup.find('CRUD_TYPE', false),
					radioshow: true,
					dragnode: '',
					radio2: '',
					saveBtnShow: true,
					qryresultSelections: [],
					filterGrid: {
						// 系统参数当前行
						currentRow: null,
						// 系统参数多选ID
						multipleSelection: '',
						data: null,
						subdata: null,
						total: null,
						loading: true,
						subloading: true
					},
					tableData: [{
						summColumnId: '',
						summTypeId: '',
						summNameId: '',
						summColumn: '',
						summType: '',
						summName: ''
					}, {
						summColumn: '',
						summType: '',
						summName: ''
					}, {
						summColumn: '',
						summType: '',
						summName: ''
					}, {
						summColumn: '',
						summType: '',
						summName: ''
					}, {
						summColumn: '',
						summType: '',
						summName: ''
					}],
					busDataMonth: {
						dataMonth: new Date(new Date().getTime() - 24 * 60 * 60 * 1000)
					}, // 客户业务月份选择form数据
					custGroupVisible: false,
					custGroupFields: [{
						columnCount: 2,
						fields: [{
								field: 'custGroupName',
								label: '客群名称',
								rules: [{
									required: true,
									message: '必填项',
									trigger: 'blur'
								}]
							},
							{
								field: 'custGroupStatus',
								label: '客群状态',
								type: 'select',
								dataCode: 'CUST_GROUP_STATE',
								rules: [{
									required: true,
									message: '必填项',
									trigger: 'blur'
								}]
							}
						]
					}],
					addCustGroupButtons: [{
							label: '保存',
							type: 'primary',
							hidden: false,
							op: 'submit',
							click: function(model, valid) {
								if (valid) {
									// model.lastChgUsr = me.userId;
									me.saveCustGroup(model);
									me.custGroupVisible = false;
									// me.$refs.qryresult.remoteData();

								}
							}
						},
						{
							label: '取消',
							hidden: false,
							click: function(model) {
								me.custGroupVisible = false;
							}
						}
					]
				};
			},
			computed: {
				status: function() {
					// 判断加入方式是否是加入已有客户群
					return this.formdata.addType === '1';
				}
			},
			mounted: function() {
				var me = this;
				this.viewTitle.EXECUTE = '执行方案';
				// 设置操作符
				yufp.lookup.bind('CONDITION_FUNC', function(data) {
					me.signOptions = data;
				});
				// 设置汇总类型
				yufp.lookup.bind('TYPE_OPTION', function(data) {
					me.typeOptions = data;
				});
				// 设置查询条件字段属性值样式
				yufp.lookup.bind('COMBO_SELECTBOX', function(data) {
					me.comboSelectOptions = data;
				});
				yufp.lookup.bind('NUM_DATABOX', function(data) {
					me.numDataOptions = data;
				});
				yufp.lookup.bind('TEXTBOX', function(data) {
					me.textOptions = data;
				});
				yufp.lookup.bind('RADIO_COMBOBOX', function(data) {
					me.selectOptions = data;
				});
				yufp.lookup.bind('RADIO_COMBOBOX', function(data) {
					me.radioComboOptions = data;
				});
				yufp.lookup.bind('LABELBOX', function(data) {
					me.labelOptions = data;
				});
			},
			methods: {
				resetMainCustGroupFn: function() {
					this.$refs.custSearchForm.resetFields();
				},
				selectcustGroupCancelFn: function() {
					var _this = this;
					_this.selectCustGroupDialogVisible = false;
				},
				searchCustGroupFn: function() {
					var _this = this;
					var param = {
						condition: JSON.stringify({
							custGroupName: _this.$refs.custSearchForm.formdata.custGroupName ? _this.$refs.custSearchForm.formdata.custGroupName :
								null,
							userId: yufp.session.userId,
							orgCode: yufp.session.org.id
						})
					};
					_this.$refs.selectCustGroupTable.remoteData(param);
				},
				/**
				 * 方案新增、修改、查看对话框切换
				 */
				switchStatus: function(viewType, editable) {
					var _this = this;
					_this.viewType = viewType;
					_this.planConfVisible = true;
				},
				/**
				 * 重置方案信息
				 */
				resetSolutionFn: function() {
					this.list = [];
					this.colunmNamelist = [{
						'name': '客户编号',
						'id': '',
						'ename': 'custIdBase',
						'fixedFlag': true
					}, {
						'name': '客户名称',
						'id': '',
						'ename': 'custNameBase',
						'fixedFlag': true
					}];
					this.resultColunmNamelist = [{
						'name': '客户编号',
						'id': '',
						'ename': 'custIdBase',
						'fixedFlag': true
					}, {
						'name': '客户名称',
						'id': '',
						'ename': 'custNameBase',
						'fixedFlag': true
					}];
					this.conlist = [];
					this.columnOptions = [];
					this.solutionlist = [];
					this.firstOptions = [];
					this.secondOptions = [];
					this.thirdOptions = [];
					this.fourOptions = [];
					this.fiveOptions = [];
					this.chartTagOptions = [];
					this.chartTargetOptions = [];
					this.xchartTagOptions = [];
					this.ychartTargetOptions = [];
				},

				/**
				 * 加载方案信息显示
				 */
				loadDatasetInfoShow: function() {
					this.resetSolutionFn();
					var row = this.$refs.planTable.selections[0];
					var ssId = row.id; // 方案编号
					var ssResult = row.ssResult.split(','); // 取出显示列3354,3346
					var ssSort = row.ssSort.split(','); // 取出显示列排序1,1
					// 显示列回显
					for (var i = 0; i < ssResult.length; i++) {
						var sslist = {};
						sslist.id = ssResult[i];
						sslist.orderType = ssSort[i];
						// 根据后台id遍历树对应名称
						var tempTreeData = vm.treedata;
						for (var j = 0; j < tempTreeData.length; j++) {
							if (tempTreeData[j].nodeId == sslist.id) {
								sslist.name = tempTreeData[j].name;
								sslist.fieldname = tempTreeData[j].ename;
								sslist.tabname = tempTreeData[j].value;
								// 将字段转为驼峰形式
								var foos = sslist.fieldname;
								var ename = foos.toLowerCase().split('_');
								for (var k = 1; k < ename.length; k++) {
									ename[k] = ename[k].charAt(0).toUpperCase() + ename[k].substring(1);
								}
								ename = ename.join('');
								if (ename == 'tagNum') {
									sslist.ename = ename + ssResult[i];
									sslist.orderOption = [{
										key: '1',
										value: '不排序'
									}];
								} else {
									sslist.ename = ename;
									sslist.orderOption = [{
										key: '1',
										value: '不排序'
									}, {
										key: '2',
										value: '升序'
									}, {
										key: '3',
										value: '降序'
									}];

								}
							}
						}
						// 根据后台id遍历树对应名称
						sslist.indexs = i;
						vm.$set(vm.dataTemp, sslist.indexs, {
							proPer: sslist.name,
							orderType: sslist.orderType,
							fixedFlag: false
						});
						vm.conlist.push(sslist);
						console.log(sslist);
						if (sslist.id != '1000' && sslist.id != '1001') { //客户编号客户名称固定展示
							vm.colunmNamelist.push(sslist);
						}
						vm.resultColunmNamelist.push(sslist);
						vm.solutionlist.push(sslist);
					}
					// 查询条件回显ss_col_val
					yufp.service.request({
						method: 'GET',
						async: false,
						url: backend.appOcaService + '/api/flexibleQueryCon/getSCol',
						data: {
							ssId: ssId
						},
						callback: function(code, message, response) {
							if (response.data != null) {
								for (var i = 0; i < response.data.length; i++) {
									var collist = {};
									collist.id = response.data[i].ssColItem;
									// 根据后台id遍历树对应名称
									var tempTreeData = vm.treedata;
									for (var j = 0; j < tempTreeData.length; j++) {
										if (tempTreeData[j].nodeId == collist.id) {
											collist.name = tempTreeData[j].name;
											collist.tabname = tempTreeData[j].value;
											collist.fieldname = tempTreeData[j].fname;
											collist.fieldType = tempTreeData[j].fieldType;
											collist.colType = tempTreeData[j].ctype;
											collist.notes = tempTreeData[j].notes;
											// 将字段转为驼峰形式
											var foos = tempTreeData[j].ename;
											var ename = foos.toLowerCase().split('_');
											for (var k = 1; k < ename.length; k++) {
												ename[k] = ename[k].charAt(0).toUpperCase() + ename[k].substring(1);
											}
											collist.ename = ename.join('');
										}
									}
									// 根据后台id遍历树对应名称
									var item = {};
									var selection = {};
									item.ctype = 'input';
									item.unit = '';
									item.options = [];
									selection.ctype = 'select';
									if (collist.colType == 'VARCHAR' || collist.colType == 'CHAR') { // 文本框
										selection.options = vm.textOptions;
									} else if (collist.colType == 'NUMBER' || collist.colType == 'DECIMAL' || collist.colType == 'INT') { // 数字框
										selection.options = vm.numDataOptions;
									} else if (collist.colType == 'DATE' || collist.colType == 'TIMESTMP') { // 日期框
										selection.options = vm.numDataOptions;
									}
									if (collist.notes != null && collist.notes != '' && collist.notes != undefined) {
										yufp.lookup.bind(collist.notes, function(data) {
											item.options = data;
											item.ctype = 'select';
										});
									}
									if (collist.fieldType == '7' && collist.fieldname != '' && collist.fieldname != undefined) {
										item.ctype = collist.fieldname;
									}
									// if(collist.fieldType == '8' && collist.fieldname != '' && collist.fieldname != undefined){
									//     item.ctype = 'select';
									//     yufp.service.request({
									//       url: backend.appOcaService + '/api/tagManage/gettagByGroup',
									//       method: 'GET',
									//       async: false,
									//       data: {
									//                   condition: JSON.stringify({
									//                     tagGroup: collist.fieldname,
									//                   })
									//                 },
									//       callback: function (code, message, response) {
									//         if (code == '0') {
									//             item.options = [];
									//             for(var K = 0;K<response.data.length;K++){
									//                item.options.push({key: response.data[K].tagNum, value: response.data[K].tagName});
									//             }
									//       }
									//       }
									//     });
									// }
									collist.items = item;
									collist.section = selection;
									collist.signOp = response.data[i].ssColOp;
									collist.signVal = response.data[i].ssColValue;
									collist.radio2 = response.data[i].ssColGjoin;
									collist.and = '并且';
									collist.or = '或者';
									if (collist.radio2 == 'and') {
										collist.radio2 = '并且';
									} else if (collist.radio2 == 'or') {
										collist.radio2 = '或者';
									} else {
										collist.radio2 = '';
									}
									var len = Object.keys(vm.dataSqlTemp);
									collist.index = len.length;
									vm.$set(vm.dataSqlTemp, collist.index, {
										radio2: collist.radio2,
										proPer: collist.name,
										signOp: collist.signOp,
										signVal: collist.signVal
									});
									/* vm.$nextTick(function () {
									     //yufp.extend(true, vm.dataSqlTemp, item);
									     vm.dataSqlTemp[collist.index] =  {
									                                         radio2: collist.radio2,
									                                         proPer: collist.name,
									                                         signOp: collist.signOp,
									                                         signVal: collist.signVal
									                                       }
									 })*/
									/*vm.dataSqlTemp[collist.index] = {
									  radio2: collist.radio2,
									  proPer: collist.name,
									  signOp: collist.signOp,
									  //signVal: collist.signVal
									}
									var json = {
									  signVal: collist.signVal
									};
									var item = {};
									item[collist.index] = json;
									vm.$nextTick(function () {
									  yufp.extend(true, vm.dataSqlTemp, item);
									})*/
									vm.list.push(collist);; // 设置查询条件时，同步设置为显示列
								}
							}
						}
					});
				},
				/**
				 * 删除方案
				 */
				datasetDeleteFn: function() {
					var ids = ''; // 记录要删除的记录id
					var selecttions = this.$refs.planTable.selections;
					if (selecttions == undefined || selecttions == null || selecttions.length == 0) {
						vm.$message({
							message: '请选择需要删除的方案!'
						});
						return false;
					}
					// 拼接要删除方案id
					for (var i = 0; i < selecttions.length; i++) {
						if (i > 0) {
							ids += ',';
						}
						ids += selecttions[i].id;
					}
					//
					vm.$confirm('确认要删除选择的方案?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning',
						callback: function(action) {
							if (action === 'confirm') {
								yufp.service.request({
									url: backend.appOcaService + '/api/flexibleQuerySolution/batchDeleteSolution/' + ids,
									method: 'post',
									data: vm.filterGrid.currentRow,
									callback: function(code, message, response) {
										if (code == '0') {
											vm.$message({
												message: '删除成功!'
											});
											vm.$refs.planTable.remoteData();
										} else {
											vm.$message({
												message: '删除失败!'
											});
										}
									}
								});
							}
						}
					});
				},
				/**
				 * 指标树加载完成
				 */
				getdata: function(value) {
					this.treedata = value;
					this.treedataLoaded = true;
					if (this.treedataLoadedLoadInfoShow) {
						this.loadDatasetInfoShow(); // 加载方案信息显示
						this.treedataLoadedLoadInfoShow = false;
					}
				},
				/**
				 * 查询指标树中的指标
				 */
				filterTreedata: function() {
					var _this = this;
					_this.$refs.flexytree.filter(_this.filterTreedataValue);
				},
				/**
				 * 指标树过滤指标显示
				 */
				filterNode: function(value, data, node) {
					if (!value) {
						return true;
					}
					return data.name.indexOf(value) != -1;
				},
				/**
				 * 指标树操作
				 */
				allowDroprow: function() {
					return false;
				},
				/**
				 * 拖拽开始
				 */
				handleDragStart: function(node, ev) {
					this.dragnode = node;
				},
				allowDrop: function(event) {
					if (this.dragnode.childNodes.length == 0) {
						this.addTabInfoFn(this.dragnode.data);
					}
				},
				allowDrop1: function(event) {
					if (this.dragnode.childNodes.length == 0) {
						this.addResultColFn(this.dragnode.data);
					}
				},
				allowDropover: function(event) {
					event.preventDefault();
				},
				/**
				 * 查询条件插入子节点
				 */
				childrenallowDrop: function(event, index) {
					event.stopPropagation();
					if (this.dragnode && this.dragnode.childNodes && this.dragnode.childNodes.length == 0) {
						this.addChildInfoFn(this.dragnode.data, index);
						// this.list[index].children.push('1');
					}
				},
				Dragover: function(event) {
					event.preventDefault();
				},
				/**
				 * 添加查询条件 - 拖拽释放
				 */
				addTabInfoFn: function(node) {
					var _this = this;
					if (node) {
						var dataList = {};
						// dataList.index = _this.list.length;
						var len = Object.keys(_this.dataSqlTemp);
						dataList.index = len.length;
						// dataList.indexs = _this.conlist.length;
						dataList.name = node.name;
						dataList.id = node.nodeId;
						dataList.fieldType = node.fieldType;
						var flag = false; // 是否已经添加
						for (var i = 0; i < _this.list.length; i++) {
							if (_this.list[i].id == dataList.id && dataList.fieldType == '8') {
								flag = true;
								break;
							}
						}
						if (!flag) {
							// 将字段转为驼峰形式
							var foo = node.ename;
							var ename = foo.toLowerCase().split('_');
							for (var i = 1; i < ename.length; i++) {
								ename[i] = ename[i].charAt(0).toUpperCase() + ename[i].substring(1);
							}
							dataList.ename = ename.join('');
							dataList.children = [];
							if (_this.list.length == 0) {
								dataList.and = '';
								dataList.or = '';
								// _this.radio2 = '0'; // TODO why
							} else {
								dataList.and = '并且';
								dataList.or = '或者';
								// _this.radio2 = '2'; // TODO why
							}
							// 查询拖拽的字段类型
							var param = {
								condition: JSON.stringify({
									id: dataList.id
								})
							};
							_this.conditionField = [];
							yufp.service.request({
								method: 'GET',
								async: false,
								url: '/api/flexibleQuery/showColType',
								data: param,
								callback: function(code, message, response) {
									var data = response.data;
									// 数据类型
									dataList.colType = data[0].colType;
									_this.getConditionField(_this.conditionField, data[0]);
									dataList.section = _this.conditionField[0].section;
									dataList.items = _this.conditionField[0].item;
									// 查询条件界面添加查询条件显示
									_this.$set(_this.dataSqlTemp, dataList.index, {
										radio2: '',
										proPer: dataList.name,
										signOp: '',
										signVal: ''
									});
									// vm.dataSqlTemp[dataList.index].signVal = response.data[0].fName;
									vm.dataSqlTemp[dataList.index].radio2 = '并且';
									// vm.dataSqlTemp[dataList.index].signOp = dataList.section.options[0].key;
									// 保存查询条件到查询条件列表
									_this.list.push(dataList);

								}
							});
							//
							setTimeout(function() { // 延时释放
								_this.addResultColFn(node); // 设置查询条件时，同步设置为显示列
							}, 1000);

						}
					}
				},
				/**
				 * 添加查询条件 - 拖拽释放（子查询条件）
				 */
				addChildInfoFn: function(node, index) {
					var _this = this;
					if (node) {
						var dataList = {};
						// dataList.index = _this.list.length;
						var len = Object.keys(_this.dataSqlTemp);
						dataList.index = len.length;
						// dataList.indexs = _this.conlist.length;
						dataList.name = node.name;
						dataList.id = node.nodeId;
						// 将字段转为驼峰形式
						var foo = node.ename;
						var ename = foo.toLowerCase().split('_');
						for (var i = 1; i < ename.length; i++) {
							ename[i] = ename[i].charAt(0).toUpperCase() + ename[i].substring(1);
						}
						dataList.ename = ename.join('');
						if (_this.list.length == 0) {
							dataList.and = '';
							dataList.or = '';
							dataList.radio2 = '0';
						} else {
							dataList.and = '并且';
							dataList.or = '或者';
							dataList.radio2 = '2';
						}
						var flag = false; // 是否已经添加
						for (var i = 0; i < _this.list.length; i++) {
							if (_this.list[i].id == dataList.id) {
								flag = true;
								break;
							}
						}
						// 查询拖拽的字段类型
						if (!flag) {
							var param = {
								condition: JSON.stringify({
									id: dataList.id
								})
							};
							yufp.service.request({
								method: 'GET',
								url: '/api/flexibleQuery/showColType',
								data: param,
								callback: function(code, message, response) {
									var data = response.data;
									// 数据类型
									dataList.colType = data[0].colType;
									_this.getConditionField(_this.conditionField, data[0]);
									dataList.section = _this.conditionField[0].section;
									dataList.items = _this.conditionField[0].item;
									// 查询条件界面添加查询条件显示
									_this.$set(_this.dataSqlTemp, dataList.index, {
										radio2: '2',
										proPer: dataList.name,
										signOp: '',
										signVal: ''
									});
									vm.dataSqlTemp[dataList.index].signVal = response.data[0].fName;
									vm.dataSqlTemp[dataList.index].radio2 = '并且';
									vm.dataSqlTemp[dataList.index].signOp = dataList.section.options[0].key;
									// 保存查询条件到查询条件列表
									if (_this.list[index].children == null) {
										_this.list[index].children = [];
									}
									_this.list[index].children.push(dataList);
								}
							});
						}
						//
						_this.addResultColFn(node); // 设置查询条件时，同步设置为显示列

					}
				},
				/**
				 * 删除查询条件
				 */
				queryCondelTableRow: function(index, rows) {
					var id = rows[index].id;
					var c = 0;
					var count = 0;
					window.console.info(this.list);
					window.console.info(count);
					window.console.info('----------------------------');
					this.list.splice(index, 1);
					this.conlist.splice(index, 1);

					for (var j = 0; j < this.list.length; j++) {
						if (this.list[j].id == id) {
							count++;
						}
					}
					window.console.info(this.list);
					window.console.info(count);
					for (var i = 0; i < this.colunmNamelist.length; i++) {
						if (this.colunmNamelist[i].id == id && count < 1) {
							this.colunmNamelist.splice(i, 1);
							this.solutionlist.splice(index, 1);
						}
					}
					var tempTreeData = vm.treedata;
					for (var j = 0; j < tempTreeData.length; j++) {
						if (tempTreeData[j].nodeId == id && tempTreeData[j].fieldType == '8') {
							for (var i = 0; i < this.conlist.length; i++) {
								if (this.conlist[i].id == id) {
									this.conlist.splice(i, 1);
								}
							}
						}
					}

					window.console.info("LLLLLLLLLLLLLLL");
					window.console.info(this.list);
					window.console.info(this.conlist);
					window.console.info(this.colunmNamelist);
				},
				/**
				 * 删除查询条件 - 子查询条件
				 */
				delSconChildInfoFn: function(index, children) {
					children.splice(index, 1);
					this.$forceUpdate(); // v-for嵌套，强制刷新
				},
				/**
				 * 添加显示列 - 拖拽释放
				 */
				addResultColFn: function(node) {
					console.log('列释放', node);
					var orderOption = '';
					if (node.fieldType != '8') {
						orderOption = [{
							key: '1',
							value: '不排序'
						}, {
							key: '2',
							value: '升序'
						}, {
							key: '3',
							value: '降序'
						}];
					} else {
						orderOption = [{
							key: '1',
							value: '不排序'
						}];
					}
					var _this = this;
					if (node == undefined || node == null || node == '') {
						return;
					}
					var dataList = {};
					var len = Object.keys(_this.dataSqlTemp);
					dataList.index = len.length;
					dataList.indexs = Object.keys(_this.dataTemp).length; // _this.conlist.length;
					dataList.name = node.name;
					dataList.id = node.nodeId;
					dataList.fixedFlag = false;
					dataList.orderOption = orderOption;
					// 将字段转为驼峰形式
					var foo = node.ename;
					var ename = foo.toLowerCase().split('_');
					for (var i = 1; i < ename.length; i++) {
						ename[i] = ename[i].charAt(0).toUpperCase() + ename[i].substring(1);
					}
					//
					ename = ename.join('');
					if (ename == 'tagNum') {
						dataList.ename = ename + dataList.id;
					} else {
						dataList.ename = ename;
					}
					dataList.children = [];
					if (_this.conlist.length == 0) {
						dataList.and = '';
						dataList.or = '';
						_this.radio2 = '0';
					} else {
						dataList.and = '并且';
						dataList.or = '或者';
						_this.radio2 = '2';
					}
					//
					var flag = false; // 是否已经添加
					for (var i = 0; i < _this.conlist.length; i++) {
						if (_this.conlist[i].id == dataList.id) {
							flag = true;
							break;
						}
					}
					if (!flag) {
						_this.conlist.push(dataList);
						_this.$set(_this.dataTemp, dataList.indexs, {
							proPer: dataList.name,
							orderType: ''
						});
						vm.dataTemp[dataList.indexs].orderType = '1';
						_this.columnOptions = _this.list;
						_this.chartTagOptions = _this.list;
						// _this.chartTargetOptions = _this.list;
						_this.xchartTagOptions = _this.list;
						// _this.ychartTargetOptions = _this.list;
						_this.solutionlist.push(dataList);
						console.log(dataList);
						if (dataList.id != '1000' && dataList.id != '1001') { //客户编号客户名称固定展示
							_this.colunmNamelist.push(dataList);
						}
						_this.resultColunmNamelist.push(dataList);
						_this.customersColumnOptions = _this.list;
						_this.firstOptions = _this.list;
						_this.secondOptions = _this.list;
						_this.thirdOptions = _this.list;
						_this.fourOptions = _this.list;
						_this.fiveOptions = _this.list;
					}

					if (node.fieldType == '8' && !flag) {
						var flag = false; // 是否已经添加
						for (var i = 0; i < this.list.length; i++) {
							if (_this.list[i].id == dataList.id) {
								flag = true;
								break;
							}
						}
						if (!flag) {
							_this.addTabInfoFn(node);
						}
					}
				},
				/**
				 * 删除显示列
				 */
				delResultColFn: function(index, rows) {
					var id = rows[index].id;
					this.conlist.splice(index, 1);
					//this.colunmNamelist.splice(index + 2, 1);
					console.log(id)
					for (var i = 0; i < this.colunmNamelist.length; i++) {
						if (this.colunmNamelist[i].id == id) {
							this.colunmNamelist.splice(i, 1);
							this.solutionlist.splice(index, 1);
						}
					}

					var tempTreeData = vm.treedata;
					for (var j = 0; j < tempTreeData.length; j++) {
						if (tempTreeData[j].nodeId == id && tempTreeData[j].fieldType == '8') {
							for (var i = 0; i < this.list.length; i++) {
								if (this.list[i].id == id) {
									this.list.splice(i, 1);
								}
							}
						}
					}
					window.console.info("LLLLLLLLLLLLLLL");
					window.console.info(tempTreeData);
					// this.$delete(this.dataTemp, index);
				},
				// 获取字段并且设置属性
				getConditionField: function(arr, field) {
					var selection = {};
					var obj = {};
					var itempart = [
						[]
					];
					var item = {};
					selection.ctype = 'select';
					item.type = '';
					item.options = '';
					item.unit = '';
					if (field.colType == 'VARCHAR' || field.colType == 'CHAR') { // 文本框
						selection.options = this.textOptions;
					} else if (field.colType == 'NUMBER' || field.colType == 'DECIMAL' || field.colType == 'INTEGER') { // 数字框
						selection.options = this.numDataOptions;
					} else if (field.colType == 'DATE' || field.colType == 'TIMESTMP') { // 日期框
						selection.options = this.numDataOptions;
					}
					if (field.fieldType == '1') { // 文本框
						selection.options = this.textOptions;
						item.ctype = 'input';
					} else if (field.fieldType == '2') { // 数字框
						selection.options = this.numDataOptions;
						item.ctype = 'input';
						item.unit = '';
						itempart[0].push(item);
					} else if (field.fieldType == '3') { // 日期框
						selection.options = this.numDataOptions;
						item.ctype = 'datepicker';
						item.type = 'date'; // daterange
						itempart[0].push(item);
					} else if (field.fieldType == '4') { // 下拉框
						selection.options = this.selectOptions;
						item.ctype = 'select'
						yufp.lookup.bind(field.notes, function(data) {
							item.options = data;
						});
					} else if (field.fieldType == '5') { // 单选框
						// selection.options = this.radioComboOptions;
						item.ctype = 'select';
						yufp.lookup.bind(field.notes, function(data) {
							item.options = data;
						});
					} else if (field.fieldType == '6') { // 多选框
						// selection.options = this.comboSelectOptions;
						item.ctype = 'select';
						yufp.lookup.bind(field.notes, function(data) {
							item.options = data;
						});
					} else if (field.fieldType == '7') { // 放大镜
						selection.options = this.selectOptions;
						item.ctype = field.fName;
						// item.ctype ='yufp-duty-selector';
					}
					// else if (field.fieldType == '8') { // 标签组
					//         selection.options = this.labelOptions;
					//         item.ctype = 'select';
					//         yufp.service.request({
					//           url: backend.appOcaService + '/api/tagManage/gettagByGroup',
					//           method: 'GET',
					//           data: {
					//                       condition: JSON.stringify({
					//                         tagGroup: field.fName,
					//                       })
					//                     },
					//           callback: function (code, message, response) {
					//             if (code == '0') {
					//               var valueList = []
					//               for(var i = 0;i<response.data.length;i++){
					//                  valueList.push({key: response.data[i].tagNum, value: response.data[i].tagName});
					//               }
					//               item.options = valueList;
					//             }
					//           }
					//         });
					//       }

					obj.section = selection;
					obj.item = item;
					arr.push(obj);
				},
				/**
				 * 查询结果分页事件
				 */
				qryResultPageChangeFn: function(val) {
					var _this = this;
					_this.pageData.page = val;
					if (_this.repeatTrigger) {
						_this.repeatTrigger = false;
					} else {
						_this.querySolutionRstFn();
					}
				},
				/**
				 * 查询结果分页大小改变事件
				 */
				qryResultSizeChangeFn: function(size) {
					var _this = this;
					_this.pageData.size = size;
					if (_this.repeatTrigger) {
						_this.repeatTrigger = false;
					} else {
						if (_this.pageData.page !== 1) {
							_this.pageData.page = 1;
							_this.repeatTrigger = true;
						}
						_this.querySolutionRstFn();
					}
				},
				/**
				 * 查询结果不分页所有
				 */
				qryResultAll: function() {
					var _this = this;
					// _this.pageData.size = size;
					_this.repeatTrigger = false;
					_this.querySolutionRstFn();
					// if (_this.repeatTrigger) {
					// 	_this.repeatTrigger = false;
					// } else {
					// 	if (_this.pageData.page !== 1) {
					// 		_this.pageData.page = 1;
					// 		_this.repeatTrigger = true;
					// 	}
					// 	_this.querySolutionRstFn();
					// }
				},
				/**
				 * 保存方案 - 新增/修改
				 */
				saveSolutionFn: function() {
					var _this = this;
					if (!_this.checkSolution()) {
						return;
					}
					_this.solutionNameSetDialogVisible = true;
					_this.solutionNameSetFormData.ssName = '';
					if (_this.viewType == 'ADD') {
						_this.$nextTick(function() {
							_this.solutionNameSetFormData.ssName = '';
						});
					} else if (this.viewType == 'EDIT') {
						_this.$nextTick(function() {
							_this.solutionNameSetFormData.ssName = _this.selectedSsName;
						});
					}
				},
				/**
				 * 关闭方案对话框
				 */
				closeSolutionDialogFn: function() {
					this.planConfVisible = false;
				},
				/**
				 * 检查方案（保存方案前进行检查）
				 */
				checkSolution: function() {
					var _this = this;
					// 检查查询条件是否设置
					if (_this.list.length == 0) {
						vm.$message({
							message: '请先选择查询条件',
							type: 'warning'
						});
						return false;
					}
					// 检查显示列是否设置
					if (_this.solutionlist.length == 0) {
						vm.$message({
							message: '请先选择显示列',
							type: 'warning'
						});
						return false;
					}
					// 检查查询条件，并生成查询条件数据
					_this.conditionAttrs = [];
					for (var i = 0; i < _this.list.length; i++) {
						_this.qryarr = []; // TODO 做什么用的
						// 查询条件
						var info = {};
						info.ssColItem = _this.list[i].id;
						if (vm.dataSqlTemp[_this.list[i].index].signOp == null || vm.dataSqlTemp[_this.list[i].index].signOp === '' ||
							vm.dataSqlTemp[_this.list[i].index].signOp == undefined) {
							_this.$message('操作符不能为空');
							return false;
						}
						// if (vm.dataSqlTemp[_this.list[i].index].signVal == null || vm.dataSqlTemp[_this.list[i].index].signVal ===
						// 	'' || vm.dataSqlTemp[_this.list[i].index].signVal == undefined) {
						// 	_this.$message('属性值不能为空');
						// 	return false;
						// }
						info.ssColOp = vm.dataSqlTemp[_this.list[i].index].signOp;
						info.ssColValue = vm.dataSqlTemp[_this.list[i].index].signVal;
						info.ssColGjoin = vm.dataSqlTemp[_this.list[i].index].radio2;
						info.ssColJoin = '';
						info.ssColGorder = i;
						info.ssColOrder = '0';
						info.ssId = _this.selectedSsId;
						if (info.ssColGjoin == '并且') {
							info.ssColGjoin = 'and';
						} else if (info.ssColGjoin == '或者') {
							info.ssColGjoin = 'or';
						}
						_this.conditionAttrs.push(info);
					}
					// 检查显示列，并生成显示列数据
					_this.solution = [];
					var resultinfo = {};
					var ssResult = '';
					var ssSort = '';
					for (var i = 0; i < _this.solutionlist.length; i++) {
						ssResult += _this.solutionlist[i].id;
						ssSort += vm.dataTemp[_this.solutionlist[i].indexs].orderType;
						if (i != _this.solutionlist.length - 1) {
							ssResult += ',';
							ssSort += ',';
						}
					}
					resultinfo.ssResult = ssResult;
					resultinfo.ssSort = ssSort;
					resultinfo.ssType = '1';
					resultinfo.ssName = _this.solutionNameSetFormData.ssName;
					resultinfo.id = _this.selectedSsId;
					resultinfo.topNum = _this.limitNum;
					_this.solution.push(resultinfo);
					return true;
				},
				/**
				 * 执行新增/更新方案
				 */
				doSaveSolutionFn: function() {
					var _this = this;
					_this.solution[0].ssName = _this.solutionNameSetFormData.ssName;
					_this.insertSolution();
				},
				/**
				 * 关闭方案名称设置对话框
				 */
				closeSolutionNameSetDialogFn: function() {
					this.solutionNameSetDialogVisible = false;
				},
				/**
				 * 新增方案
				 */
				insertSolution: function() {
					var _this = this;
					var userId = yufp.session.userId;
					console.log('1:', _this.conditionAttrs);
					console.log('2:', _this.solution);
					yufp.service.request({
						url: backend.appOcaService + '/api/flexibleQuerySolution/saveSolution/',
						method: 'POST',
						data: {
							scolData: JSON.stringify(_this.conditionAttrs),
							solutionData: JSON.stringify(_this.solution)
						},
						callback: function(code, message, response) {
							if (code == '0') {
								_this.$message({
									message: '新增方案成功!',
									type: 'info'
								});
								_this.solutionNameSetDialogVisible = false;
								_this.planConfVisible = false;
								_this.$nextTick(function() {
									_this.$refs.planTable.remoteData();
								});
							} else {
								_this.$message({
									message: '新增方案失败!',
									type: 'warning'
								});
								_this.solutionNameSetDialogVisible = false;
							}
						}
					});
				},
				// 数据格式化
				dataFormatter: function(row, column, cellValue) {
					if (cellValue == undefined || cellValue == null || cellValue == '') {
						return cellValue;
					}
					if (column.label == '存款余额(元)' ||
						column.label == '存款余额比年初(元)' ||
						column.label == '存款年日均(元)' ||
						column.label == '存款年日均比年初(元)' ||
						column.label == '活期存款余额(元)' ||
						column.label == '定期存款余额(元)' ||
						column.label == '协议存款余额(元)' ||
						column.label == '结构性存款余额(元)' ||
						column.label == '保本理财余额(元)' ||
						column.label == '贷款余额(元)' ||
						column.label == '贷款年日均(元)' ||
						column.label == '表外敞口余额(元)' ||
						column.label == '授信额度(元)' ||
						column.label == '员工规模' ||
						column.label == '注册资本金') {
						var formatterValue = yufp.util.moneyFormatter(cellValue, 2);
						return formatterValue;
					} else if (column.label == '成立日期') {
						var tmpValue = cellValue;
						if (tmpValue.length == 8) {
							tmpValue = cellValue.substring(0, 4) + '-' + cellValue.substring(4, 2) + '-' + cellValue.substring(6);
							return tmpValue;
						} else {
							return tmpValue;
						}
					} else {
						return cellValue;
					}
				},
				rowClickFn: function(selection, row) {
					var _this = this
					_this.selections = selection;
					// 用于单个修改
					_this.filterGrid.currentRow = row;
					_this.loadDatasetInfoShow();
				},
				/** tab点击事件*/
				handleClick: function() {
					var _this = this;
					if (this.activeName == 'first') {
						_this.colv.spanS = 14;
						_this.colv.spanR = 6;
						_this.solshow = true;
						_this.showdelbtn = true;
					} else {
						_this.colv.spanS = 20;
						_this.colv.spanR = 0;
						_this.solshow = false;
						_this.showdelbtn = false;
					}
				},
				/**
				 * 选择查询结果的表格数据
				 */
				selectionChange: function(selection) {
					this.qryresultSelections = selection;
				},
				rowClick: function(row, event, column) {
					this.qryresultSelections = row;
				},
				/**
				 * 查询结果
				 */
				querySolutionRstFn: function() {
					var _this = this;
					var roleId = '';
					for (var i = 0; i < yufp.session.roles.length; i++) {
						if (yufp.session.roles[i].checked != null) {
							roleId = yufp.session.roles[i].code;
						}
					}
					if (_this.list.length == 0) {
						vm.$message({
							message: '请先选择查询条件',
							type: 'warning'
						});
						return;
					}
					// 检查显示列是否设置
					if (_this.solutionlist.length == 0) {
						vm.$message({
							message: '请先选择显示列',
							type: 'warning'
						});
						return false;
					}
					_this.loading = true;
					_this.conditionAttrs = [];
					_this.results = [];
					_this.qryarr = [];
					// 拼接参数
					for (var i = 0; i < _this.list.length; i++) {
						_this.qryarr = [];
						var info = {};
						if (vm.dataSqlTemp[_this.list[i].index].signOp == null || vm.dataSqlTemp[_this.list[i].index].signOp === '' ||
							vm.dataSqlTemp[_this.list[i].index].signOp == undefined) {
							_this.$message('操作符不能为空');
							return;
						}
						// if (vm.dataSqlTemp[_this.list[i].index].signVal == null || vm.dataSqlTemp[_this.list[i].index].signVal ===
						// 	'' || vm.dataSqlTemp[_this.list[i].index].signVal == undefined) {
						// 	_this.$message('属性值不能为空');
						// 	return;
						// }
						info.SS_COL_ITEM = _this.list[i].id;
						info.SS_COL_OP = vm.dataSqlTemp[_this.list[i].index].signOp;
						info.SS_COL_VALUE = vm.dataSqlTemp[_this.list[i].index].signVal;
						info.SS_COL_GJOIN = vm.dataSqlTemp[_this.list[i].index].radio2;
						info.SS_COL_JOIN = '';
						info.SS_COL_GORDER = i;
						info.SS_COL_ORDER = '0';
						if (info.SS_COL_GJOIN == '并且') {
							info.SS_COL_GJOIN = 'and';
						} else if (info.SS_COL_GJOIN == '或者') {
							info.SS_COL_GJOIN = 'or';
						}
						_this.qryarr.push(info);
						var childinfo = {};
						_this.conditionAttrs.push(_this.qryarr);
					}
					// 拼接显示列
					for (var i = 0; i < _this.conlist.length; i++) {
						var resultinfo = {};
						resultinfo.columnId = _this.conlist[i].id;
						resultinfo.sortType = vm.dataTemp[_this.conlist[i].indexs].orderType;
						resultinfo.columnTotle = '0';
						_this.results.push(resultinfo);
					}
					var param = {
						condition: JSON.stringify({
							conditionAttrs: _this.conditionAttrs,
							results: _this.results,
							topNum: _this.limitNum,
							isexport: '1',
							dataMonth: _this.busDataMonth.dataMonth,
							page: _this.pageData.page,
							size: _this.pageData.size,
							roleId: roleId,
							userId: yufp.session.userId,
							orgId: yufp.session.org.id
						})
					};
					_this.data = [];
					// 查询当前机构级别
					_this.dialogFormVisible1 = true;
					yufp.service.request({
						method: 'GET',
						data: param,
						url: backend.appOcaService + '/api/flexibleQuery/queryResult',
						callback: function(code, message, response) {
							if (code == 0) {
								if (response.code == 0) {
									_this.loading = false;
									var responsedata = response.data;
									_this.pageData.total = response.total;
									if (responsedata.length > 0) {
										querysql = responsedata[0].sql;
									}
									var showdata = []; // 展示数据
									// var custsdata = []; // 客户信息
									for (var i = 0; i < response.data.length; i++) {
										var aaa = {};
										var custsInfo = {};
										for (var k in response.data[i]) {
											for (var a = 0; a < _this.conlist.length; a++) {
												if (k == (_this.conlist[a].ename)) {
													aaa[_this.conlist[a].ename] = response.data[i][k];
												}
												aaa['custIdBase'] = response.data[i].custIdBase;
												aaa['custNameBase'] = response.data[i].custNameBase;
												aaa['gridId'] = response.data[i].gridId;
												aaa['secondGridId'] = response.data[i].secondGridId;
												aaa['userNo'] = response.data[i].userNo;
												// custsInfo['custIdBase'] = response.data[i].custIdBase;
												// custsInfo['gridId'] = response.data[i].gridId;
												// custsInfo['secondGridId'] = response.data[i].secondGridId;
												// custsInfo['userNo'] = response.data[i].userNo;
												// custsInfo['custNameBase'] = response.data[i].custNameBase;
												// aaa['custNameBase'] = '中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国';
											}
										}
										showdata.push(aaa);
										// custsdata.push(custsInfo);
									}
									_this.data = showdata;
									// vm.queryAllResult = showdata;
									// window.console.info(vm.queryAllResult);

								} else {
									vm.$message({
										message: response.message,
										type: 'warning'
									});
									_this.dialogFormVisible1 = false;
								}
								_this.activeName = 'third';
								_this.colv.spanS = 20;
								_this.colv.spanR = 0;
								_this.solshow = false;
								_this.showdelbtn = false;
							}
						}
					});
				},
				/*utc2beijing: function (UTCDateString) {
				  if (!UTCDateString) {
				    return '-';
				  }
				  function formatFunc (str) { // 格式化显示
				    return str > 9 ? str : '0' + str;
				  }
				  var date2 = new Date(UTCDateString); // 这步是关键
				  var year = date2.getFullYear();
				  var mon = formatFunc(date2.getMonth() + 1);
				  var day = formatFunc(date2.getDate());
				  var hour = date2.getHours();
				  var noon = hour >= 12 ? 'PM' : 'AM';
				  hour = hour >= 12 ? hour - 12 : hour;
				  hour = formatFunc(hour);
				  var min = formatFunc(date2.getMinutes());
				  var secon = formatFunc(date2.getSeconds());
				  var dateStr = year + '-' + mon + '-' + day + ' ' + noon + ' ' + hour + ':' + min + ':' + secon;
				  return dateStr;
				},*/
				exportInfoFn: function() {
					var me = this;
					me.loading = true;
					var param = me.genSearchResultParams();
					console.log("param:", param);
					this.$nextTick(function() {
						yufp.service.request({
							url: me.startUrl,
							method: 'GET',
							data: param,
							callback: function(code, message, res) {
								window.console.info('---experotRES---');
								window.console.info(res);
								if (code != 0) {
									me.$message.error(message);
									return;
								}
								var taskId = res ? res.data : false;
								if (taskId) {
									me.taskId = taskId;
									me.progressVisible = true;
									me.progressTimer = setTimeout(me.showProgressFn(), me.delay);
								} else {
									me.$message.error('导出失败！');
									me.loading = false;
								}
							}
						});
					});
				},
				/**
				 * 轮询查询进度
				 * @param {String} taskId 任务ID
				 */
				showProgressFn: function() {
					var vm = this;
					window.console.info(this.taskId);
					yufp.service.request({
						url: vm.progressUrl,
						method: 'GET',
						data: {
							taskId: vm.taskId
						},
						callback: function(code, message, res) {
							window.console.info('-----res-----');
							window.console.info(res.data.percent);
							if (code != 0) {
								vm.$message.error(message);
								return;
							}
							vm.percentage = res.data.percent;
							if (res.data.percent < 100) {
								vm.progressTimer = setTimeout(vm.showProgressFn, vm.delay);
							} else {
								vm.downloadFile();
							}
						}
					});
				},
				// 下载文件
				downloadFile: function() {
					var url = yufp.settings.ssl ? 'https://' : 'http://';
					url += yufp.settings.url;
					url += '/' + backend.appOcaService;
					url += 'api/flexibleQuery/downloadExcel?' + 'taskId=' + this.taskId;
					window.open(yufp.util.addTokenInfo(url));
					this.loading = false;
					this.exportVisible = false;
					this.progressVisible = false;
				},
				/**
				 * 生成查询和不分页的参数
				 */
				genSearchResultParams: function(forSearchResult) {
					var _this = this;
					_this.conditionAttrs = [];
					_this.results = [];
					_this.qryarr = [];
					var roleId = '';
					for (var i = 0; i < yufp.session.roles.length; i++) {
						if (yufp.session.roles[i].checked != null) {
							roleId = yufp.session.roles[i].code;
						}
					}

					// 拼接参数
					for (var i = 0; i < _this.list.length; i++) {
						_this.qryarr = [];
						var info = {};
						if (vm.dataSqlTemp[_this.list[i].index].signOp == null || vm.dataSqlTemp[_this.list[i].index].signOp === '' ||
							vm.dataSqlTemp[_this.list[i].index].signOp == undefined) {
							_this.$message('操作符不能为空');
							return;
						}
						// if (vm.dataSqlTemp[_this.list[i].index].signVal == null || vm.dataSqlTemp[_this.list[i].index].signVal ===
						// 	'' || vm.dataSqlTemp[_this.list[i].index].signVal == undefined) {
						// 	_this.$message('属性值不能为空');
						// 	return;
						// }
						info.SS_COL_ITEM = _this.list[i].id;
						info.SS_COL_OP = vm.dataSqlTemp[_this.list[i].index].signOp;
						info.SS_COL_VALUE = vm.dataSqlTemp[_this.list[i].index].signVal;
						info.SS_COL_GJOIN = vm.dataSqlTemp[_this.list[i].index].radio2;
						info.SS_COL_JOIN = '';
						info.SS_COL_GORDER = i;
						info.SS_COL_ORDER = '0';
						if (info.SS_COL_GJOIN == '并且') {
							info.SS_COL_GJOIN = 'and';
						} else if (info.SS_COL_GJOIN == '或者') {
							info.SS_COL_GJOIN = 'or';
						}
						_this.qryarr.push(info);
						var childinfo = {};
						if (_this.list[i].children && _this.list[i].children.length > 0) {
							for (var j = 0; j < _this.list[i].children.length; j++) {
								// if (vm.dataSqlTemp[_this.list[i].children[j].index].signVal == null || vm.dataSqlTemp[_this.list[i].children[
								// 		j].index].signVal === '' || vm.dataSqlTemp[_this.list[i].children[j].index].signVal == undefined) {
								// 	_this.$message('属性值不能为空');
								// 	return;
								// }
								if (vm.dataSqlTemp[_this.list[i].children[j].index].signOp == null || vm.dataSqlTemp[_this.list[i].children[
										j].index].signOp === '' || vm.dataSqlTemp[_this.list[i].children[j].index].signOp == undefined) {
									_this.$message('操作符不能为空');
									return;
								}
								childinfo.SS_COL_ITEM = _this.list[i].children[j].id;
								childinfo.SS_COL_OP = vm.dataSqlTemp[_this.list[i].children[j].index].signOp;
								childinfo.SS_COL_VALUE = vm.dataSqlTemp[_this.list[i].children[j].index].signVal;
								childinfo.SS_COL_GJOIN = '';
								childinfo.SS_COL_GORDER = i;
								childinfo.SS_COL_ORDER = j + 1;
								childinfo.SS_COL_JOIN = vm.dataSqlTemp[_this.list[i].children[j].index].radio2;
								if (childinfo.SS_COL_JOIN == '并且') {
									childinfo.SS_COL_JOIN = 'and';
								} else if (childinfo.SS_COL_JOIN == '或者') {
									childinfo.SS_COL_JOIN = 'or';
								}
							}
							_this.qryarr.push(childinfo);
						}
						_this.conditionAttrs.push(_this.qryarr);
					}
					// 拼接显示列
					for (var i = 0; i < _this.conlist.length; i++) {
						var resultinfo = {};
						resultinfo.columnId = _this.conlist[i].id;
						resultinfo.sortType = vm.dataTemp[_this.conlist[i].indexs].orderType;
						resultinfo.columnTotle = '0';
						_this.results.push(resultinfo);
					}
					if (forSearchResult) { // 查询结果
						var param = {
							condition: JSON.stringify({
								conditionAttrs: _this.conditionAttrs,
								results: _this.results,
								topNum: _this.limitNum,
								isexport: '1',
								dataMonth: _this.busDataMonth.dataMonth,
								page: _this.pageData.page,
								size: _this.pageData.size
							})
						};
						console.log('param1', param);
						return param;
					} else { // 查询结果不分页
						var param = {
							condition: JSON.stringify({
								conditionAttrs: _this.conditionAttrs,
								results: _this.results,
								topNum: _this.limitNum,
								isexport: '1',
								dataMonth: _this.busDataMonth.dataMonth,
								// size: _this.pageData.size,
								roleId: roleId,
								userId: yufp.session.userId,
								orgId: yufp.session.org.id
							})
						};
						console.log('param2', param);
						return param;
					}
				},
				//创建客群
				addCustGroupFn: function() {
					this.custGroupVisible = true;
					this.viewType = 'ADD';

					this.$nextTick(function() {
						this.$refs.datafilterForm.resetFn();
						this.$refs.datafilterForm.switch('code', 'disabled', false);
					});
				},
				saveCustGroup: function(row) {
					var _this = this;
					_this.loading = true;
					_this.filterGrid.currentRow = row;
					var selectedCustInfo = null;
					var selections = _this.qryresultSelections;
					console.log(selections);
					if (selections.length == 0) { //全部加入群组
						flag = '1';
						querysql = querysql;
					} else { //选择加入群组
						flag = '2';
					}
					var param = {
						flag: flag,
						querysql: querysql,
						custGroupInfo: _this.filterGrid.currentRow,
						custGroupPre: selections,
						roleId: roleId,
						userId: yufp.session.userId,
						userName: yufp.session.userName,
						orgId: yufp.session.org.id
					};

					yufp.service.request({
						url: backend.appCommonService + '/api/marketCustGroup/insertCusGroup',
						method: 'post',
						data: param,
						callback: function(code, message, response) {
							if (code == '0') {
								if (response.code == '0') {
									_this.loading = false;
									// _this.$message('保存成功');
									_this.$message({
										message: '保存成功'
									});
								} else {
									_this.$message({
										message: response.message,
										type: 'warning'
									});
									return false;
								}
							} else {
								_this.$message({
									message: '保存失败'
								});
							}
						}
					});
				}
			}
		});
	};
});
